package tree.tree2.symmetry.BinarySearchTree.ModifyAndConstruct;

import tree.TreeNode;

/**
 * @ClassName InsertBST
 * @Description TODO
 * @Author lenovo
 * @Date 2023-05-11 9:54
 * @Version 1.0
 * @Comment Magic. Do not touch.
 * If this comment is removed. the program will blow up
 */
public class InsertBST {


    /**
     *   3
     *      4
     *
     * @param root
     * @param val
     * @return
     */
    public TreeNode insertIntoBST(TreeNode root, int val) {
        if (root == null) return new TreeNode(val);

        if (root.val > val) {
            root.left = insertIntoBST(root.left,val);
        } else {
            root.right = insertIntoBST(root.right,val);
        }
        return root;
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(3);
        root.right = new TreeNode(4);

        InsertBST insertBST = new InsertBST();
        System.out.println(insertBST.insertIntoBST(root, 1));
    }
}